﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QD.Tools
{
    public static class TextHelper
    {
        /// <summary>
        /// 判断是否为空
        /// </summary>
        /// <param name="argList"></param>
        /// <returns></returns>
        public static bool NoEmpty(params string[] argList)
        {
            bool isOk = true;

            foreach (string arg in argList)
            {
                if (string.IsNullOrEmpty(arg))
                {
                    isOk = false;
                    break;
                }
            }

            return isOk;
        }

        /// <summary>
        /// 判断某字符在字符串中出现的次数
        /// </summary>
        /// <param name="str"></param>
        /// <param name="chart"></param>
        /// <returns></returns>
        public static int GetCount(this string str, string chart)
        {
            string _str = str.Replace(chart, "");
            return (str.Length - _str.Length) / chart.Length;
        }

        /// <summary>
        /// 简单加密
        /// </summary>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public static string StringEncoding(string txt)
        {
            char[] arrChar = txt.ToCharArray();
            string strChar = "";
            for (int i = 0; i < arrChar.Length; i++)
            {
                arrChar[i] = Convert.ToChar(arrChar[i] + 3);
                strChar = strChar + arrChar[i].ToString();
            }
            return strChar;
        }

        /// <summary>
        /// 简单解密
        /// </summary>
        /// <param name="txt"></param>
        /// <returns></returns>
        public static string StringDecoding(string txt)
        {
            char[] arrChar = txt.ToCharArray();
            string strChar = "";
            for (int i = 0; i < arrChar.Length; i++)
            {
                arrChar[i] = Convert.ToChar(arrChar[i] - 3);
                strChar = strChar + arrChar[i].ToString();
            }
            return strChar;
        }
    }
}
